using System;

namespace sdf.Code
{

	/// <summary>
	///  Throw an expection when the Stored Proc returns an error code
	/// </summary>
	public class Exceptions
	{
		public static void StoredProcReturnValue(int ProcReturnValue, string SQLCommandText, string ReturnMessage)
		{
			//combine error parameter info and raise the custom error
			throw new StoredProcReturnValueException (ReturnMessage + "...  SQL Error #" + ProcReturnValue.ToString() +
																					".  Command: " + SQLCommandText, ProcReturnValue, SQLCommandText);
		}
	}

	/// <summary>
	///  Throw an expection when the Stored Proc returns an error code
	/// </summary>
	[Serializable]
	public class StoredProcReturnValueException : System.Exception   
	{
		private readonly int _ProcReturnValue;
		private readonly string _CommandText;

		/// <summary>
		/// Constructor
		/// </summary>
		public StoredProcReturnValueException(string Message, int ProcReturnValue, string SQLCommandText)
			: base(Message)
		{
			this._ProcReturnValue = ProcReturnValue;
			this._CommandText = SQLCommandText;
		}

		/// <summary>Get the SQL command text that caused the exception</summary>
		public string CommandText
		{
			get { return this._CommandText; }
		}

		/// <summary>Get the stored proc return code that caused the exception</summary>
		public int ProcReturnValue
		{
			get { return this._ProcReturnValue; }
		}
	}
}
